package com.travel.carmen;

import java.util.HashMap;
import java.util.Map;


/**
	A Drupal Node for the Travel Mobile Application Carmen.
	 This is the Data Structure used to sync information from a device to the
	 website for users of the application. The Data Structure is transferred
	 to and from through XMLRPC service calls.
   	@author Arturo Aparicio 
   	@author Edwin Boykin 
   	@author Veena Chengalnaidu
   	@author Anton Ganeshalingam
   	@author Lakshmi Mallampati
   	@author Tarun Morton
   	@author Chantha Thoeun
*/
public class DrupalNode extends HashMap<String, Object> 
{
	private static final long serialVersionUID = 1L;
        
	// constants
	public static final int INVALID_NID = -1;
	
	// types
	public static final String TYPE_NOTE = "note";
	
	public static String NID = "nid";
	public static String TYPE = "type";
	public static String CHANGED = "changed";
	public static String TITLE = "title";
	public static String NOTE = "field_phrase";
	public static String TRANSLATION = "field_translation";
	public static String CATEGORY = "field_category";
	public static String LANGFROM = "field_src_lang";
	public static String LANGTO   = "field_tar_lang";
        
        
	/**
    	Constructs a DrupalNode that is, a Java HashMap.
	 */
	public DrupalNode() {
		super();
	}
        
        
	/**
   		Constructs a DrupalNode that is, a Java HashMap.
        @param initialCapacity the initial capacity of this hash map.
        @param loadFactor the initial load factor.
	 */
	public DrupalNode(int initialCapacity, float loadFactor) {
		super(initialCapacity, loadFactor);
	}
        
        
	/**
    	Constructs a DrupalNode that is, a Java HashMap.
        @param initialCapacity the initial capacity of this hash map.
	 */
	public DrupalNode(int initialCapacity) {
		super(initialCapacity);
	}
        
        
	/**
      	Constructs a DrupalNode that is, a Java HashMap
        @param m an abstract Map with a key of type String 
         and value of type Object
	 */
	@SuppressWarnings("unchecked")
	public DrupalNode(Map m) {
		super(m);
	}
        
        
	/**
   		Get a Node ID
        @return Node ID
	 */
	public long getNid() {
		Object nid = get(NID);
		if (nid == null) throw new RuntimeException("nid not set (null)");
		if (nid instanceof String) {
			long result = Long.parseLong((String)nid);
			put(NID, result);
			return result;
		}
		else {
			return (Long)nid;
		}
	}
        
        
	/**
     	Set the Node ID
        @param nid Node ID
	 */
	public void setNid(long nid) {
		put(NID, nid);
	}
        
        
	/**
    	Set the time stamp for a modification on this Node
        @param changed current time stamp in milliseconds
	 */
	public void setChanged(long changed) {
		put(CHANGED, changed);
	}
        
        
	/**
   		Get the Node Title
    	@return Node Titile
	 */
	public String getTitle() {
		Object o = get(TITLE);
		if (o == null) return null;
		else return o.toString();
	}
        
        
	/**
    	Set the Node Title
        @param o Node Title
	 */
	public void setTitle(String o) {
		put(TITLE, o);
	}
        
        
	/**
     	Get the Node Category
        @return Node Category
	 */
	public String getCategory() {
		Object o = get(CATEGORY);
		if (o == null) return null;
		else return o.toString();
    }
    
    
    /**
       Set the Node Category
       @param o Node Category
     */
    public void setCategory(String o) 
    {
    	Object[] array = new Object[1];
    	HashMap<String, Object> myHashMap = new HashMap<String, Object>();
    	myHashMap.put("value", o);
    	array[0] = myHashMap;
    	put(CATEGORY, array);
    }       
       
    
    /**
       Set the Node Type
       @param o Node Type
     */
    public void setType(String o) {
    	put(TYPE, o);
    }
        
    
    /**
       Get the Node Note
       @return Node Note
     */
    public String getNote() {
    	Object o = get(NOTE);
    	if (o == null) return null;
    	else return o.toString();
    }
    
    
    /**
       Set the Node Note
       @param o Node Note
     */
    public void setNote(String o) {
    	Object[] array = new Object[1];
    	HashMap<String, Object> myHashMap = new HashMap<String, Object>();
    	myHashMap.put("value", o);
    	array[0] = myHashMap;   	
    	put(NOTE, array);
    }
    
    
    /**
       Get the Node Translation
       @return Node Translation
     */
    public String getTranslatedNote() {
    	Object o = get(TRANSLATION);
    	if (o == null) return null;
    	else return o.toString();
    }
    
    
    /**
       Set the Node Translation
       @param o Node Translation
     */
    public void setTranslatedNote(String o) {
    	Object[] array = new Object[1];
    	HashMap<String, Object> myHashMap = new HashMap<String, Object>();
    	myHashMap.put("value", o);
    	array[0] = myHashMap;   	
    	put(TRANSLATION, array);
    }
    
    
    /**
       Get the Node Source Language
       @return Node Source Language
     */
    public String getFromLanguage() {
    	Object o = get(LANGFROM);
    	if (o == null) return null;
    	else return o.toString();
    }
    
    
    /**
       Set the Node Source Language
       @param o Node Source Language
     */
    public void setFromLanguage(String o) {
    	Object[] array = new Object[1];
    	HashMap<String, Object> myHashMap = new HashMap<String, Object>();
    	myHashMap.put("value", o);
    	array[0] = myHashMap;   	
    	put(LANGFROM, array);
    }
    
    
    /**
       Get the Node Target Language
       @return Node Target Language
     */
    public String getToLanguage() {
    	Object o = get(LANGTO);
    	if (o == null) return null;
    	else return o.toString();
    }
      
    
    /**
       Set the Note Target Language
       @param o Note Target Language
     */
    public void setToLanguage(String o) {
    	Object[] array = new Object[1];
    	HashMap<String, Object> myHashMap = new HashMap<String, Object>();
    	myHashMap.put("value", o);
    	array[0] = myHashMap;   	
    	put(LANGTO, array);
    }
}